package com.ruoyi.web.controller.tool;
import java.util.Hashtable;

import javax.naming.AuthenticationException;

import javax.naming.Context;

import javax.naming.NamingException;

import javax.naming.directory.DirContext;

import javax.naming.directory.InitialDirContext;

public class TestOmr {
	
	public static boolean userVerify(String user, String password){
		boolean userVerify = false;
		Hashtable<String, String> hashEnv = new Hashtable<String, String>();
        hashEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); // LDAP访问安全级别(none,simple,strong)
//      hashEnv.put(Context.SECURITY_PRINCIPAL, "cn=" + ldapProperty.getUserNo() + "," + baseDn); //AD的用户名 现场会登录失败
        hashEnv.put(Context.SECURITY_PRINCIPAL, user + "@" + "omr.bankofchina.com"); //AD的用户名 采用@域名的方式
        hashEnv.put(Context.SECURITY_CREDENTIALS, password); //AD的密码
        hashEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // LDAP工厂类
        hashEnv.put("com.sun.jndi.ldap.connect.timeout", "5000");//连接超时设置为2秒
        hashEnv.put("com.sun.jndi.ldap.read.timeout", "5000");
        hashEnv.put(Context.PROVIDER_URL, "ldap://" + "22.152.35.64" + ":" + "389");

		try {
		DirContext authContext = new InitialDirContext(hashEnv);
		userVerify = true;
		authContext.close();
		} catch (AuthenticationException authEx) {
		userVerify = false;
		} catch (NamingException namEx) {
		userVerify = false;
		}
		return userVerify;
		}	
	public static void main(String[] args) {
		System.out.println(userVerify("8219111","password01!"));
		System.out.println(userVerify("8982688","GXpass01@"));
	}
}
